import 'package:flutter/material.dart';
import 'package:flutter_demo/tmac/SkinChangePage.dart';

import 'package:flutter_demo/tmac/widget/CardviewItemWidget.dart';

import 'package:fluttertoast/fluttertoast.dart';

class OtherPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return OtherPageState();
  }
}

class OtherPageState extends State<OtherPage> with AutomaticKeepAliveClientMixin {
  Color _themeColor = Colors.blue; //当前路由主题色
  List<Widget> _list = [];
  @override
  bool get wantKeepAlive => true;
  @override
  void initState() {
    super.initState();
    setState(() {
      initData();
    });
  }

  void initData() {
    _list.add(GestureDetector(
      child: CardViewItemWidget(
          content: "换肤",
          icon: Icon(
            Icons.palette,
            size: 50,
          )),
      onTap: () {
        Navigator.push(context,
            MaterialPageRoute(builder: (BuildContext context) {
          return SkinChangePage();
        }));
      },
    ));
    _list.add(new GestureDetector(
      child: CardViewItemWidget(
          content: "更多",
          icon: Icon(
            Icons.more_horiz,
            size: 50,
          )),
      onTap: () {
        Fluttertoast.showToast(
            msg: "敬请期待",
            gravity: ToastGravity.CENTER,
            toastLength: Toast.LENGTH_LONG);
      },
    ));
  }

  @override
  Widget build(BuildContext context) {
    return Theme(
      data: ThemeData(
          primarySwatch: _themeColor, //用于导航栏、FloatingActionButton的背景色等
          iconTheme: IconThemeData(color: _themeColor) //用于Icon颜色
          ),
      child: Scaffold(
        appBar: AppBar(title: Text("主题测试")),
        body: Padding(
          padding: EdgeInsets.all(6),
          child: GridView.builder(
              itemCount: _list.length,
              gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 3,
                  crossAxisSpacing: 6,
                  childAspectRatio: 0.8),
              itemBuilder: (context, index) {
                print("index $index");
                return _list[index];
              }),
        ),
        floatingActionButton: FloatingActionButton(
            onPressed: () => //切换主题
                setState(() => _themeColor =
                    _themeColor == Colors.blue ? Colors.red : Colors.blue),
            child: Icon(Icons.toys)),
      ),
    );
  }
}
